package cn.com.tianpeidong.restaurantadmin.project.admin.pos.util;

import cn.com.tianpeidong.restaurantadmin.project.admin.pos.entity.Sale;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static cn.com.tianpeidong.restaurantadmin.project.admin.pos.constant.PosConstant.CACHE_SALE_KEY;
import static cn.com.tianpeidong.restaurantadmin.project.admin.pos.constant.PosConstant.HANG_SALE_KEY;

/**
 * @author tianpeidong
 * @version 创建时间: 19-6-1 下午5:59
 */
@Component
public class PosCacheManager {

    @Autowired
    private RedisTemplate redisTemplate;

    public void updateSale(Sale sale) {
        this.redisTemplate.opsForHash().put(CACHE_SALE_KEY, sale.getDeskId(), sale);
    }

    public Sale getSale(Long cacheId) {
        return (Sale) this.redisTemplate.opsForHash().get(CACHE_SALE_KEY, cacheId);
    }

    public void dropSale(Long cacheId) {
        redisTemplate.opsForHash().delete(CACHE_SALE_KEY, cacheId);
    }
}
